package com.aaa.forum.controller;

import com.aaa.forum.common.AppResult;
import com.aaa.forum.exception.ApplicationException;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/test")
public class TestController {

    @RequestMapping("/aaa")
    public String test() {
        return "test!";
    }

    // 测试 Exception
    @RequestMapping("/exception")
    public AppResult testException() throws Exception {
        throw new Exception("Exception");
    }

    // 测试自定义异常, ApplicationException
    @RequestMapping("/appexception1")
    public AppResult testApplicationException1() throws ApplicationException {
        throw new ApplicationException("ApplicationException");
    }

    // 测试自定义异常, ApplicationException, 携带错误信息
    @RequestMapping("/appexception2")
    public AppResult testApplicationException2() throws ApplicationException {
        throw new ApplicationException(AppResult.failed("错误信息"));
    }
}
